package org.cfan.seckill.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jdk.nashorn.internal.ir.IfNode;
import org.apache.commons.lang3.StringUtils;
import org.cfan.seckill.RandomUtils;
import org.cfan.seckill.redis.RedisDao;
import org.cfan.seckill.service.FirstSecKillService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title: FooController</p>
 * <p>Date: 17/5/11 </p>
 * <p>Description: </p>
 *
 * @author sunxinhe
 */
@Api("foo")
@RestController
@RequestMapping("/foo")
public class FooController {

    private static final Logger LOGGER = LoggerFactory.getLogger(FooController.class);

    @Autowired
    private RedisDao redisDao;

    @Autowired
    private FirstSecKillService firstSecKillService;

    @ApiOperation("a")
    @RequestMapping(value = "/a", method = RequestMethod.GET)
    public String a(
            @ApiParam(name = "arg", required = false)
            @RequestParam(name = "arg", required = false) String arg) {
        if (StringUtils.isBlank(arg)) {
            arg = "输入为空,test";
        }
        redisDao.set("a", arg, 0);
        return arg;
    }

    @ApiOperation("buy")
    @RequestMapping(value = "/buy", method = RequestMethod.GET)
    public String buy() {
        return firstSecKillService.buy();
    }


}
